from time import sleep

from selenium.common.exceptions import NoSuchElementException

from commo.tools import Commonshare

com: Commonshare = Commonshare()


# 生成随机身份证号层


def test():
    # 访问官网
    com.open_url(com.yaml('token_url', '测试版'))
    sleep(4)
    # 点击密码登录
    com.click("xpath", com.yaml('login_path', '密码登录'))
    sleep(2)
    # 定位账号框进行账号输入
    com.input_data("xpath", com.yaml('login_path', '账号输入框'), com.yaml('login', 'name'))
    sleep(2)
    # 定位密码框进行密码输入
    com.input_data("xpath", com.yaml('login_path', '密码输入框'), com.yaml('login', 'password'))
    sleep(2)
    # 点击登录按钮进行登录
    com.click("xpath", com.yaml('login_path', '登录按钮'))
    sleep(1)
    # 获取错误弹框内容
    try:
        result = com.get_text("xpath", "/html/body/div[2]/span/div/div/div/div[2]")
        return result
    except NoSuchElementException:
        return " Error: 未弹出错误框"


